package demo03;

public class FizzBuzz implements Runnable{
	private int num;
	static int n=1;
	public static Object lock=new Object();

	public FizzBuzz(int num) {
		super();
		this.num = num;
	}
	public void fizz(){
		System.out.println("fizz");
	}
	public void buzz(){
		System.out.println("buzz");
	}
	public void fizbuzzz(){
		System.out.println("fizzbuzz");
	}
	public void number(int num){
		System.out.println(num);

	}
	@Override
	public void run() {
		synchronized (lock) {
			while(n<=num){
				if(n%3==0&&n%5!=0){
					fizz();
				}else if(n%5==0&&n%3!=0){
					buzz();
				}else if(n%3==0&&n%5==0){
					fizbuzzz();
				}else{
					number(n);
				}
				n++;
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {

					e.printStackTrace();
				}
			}
		}
		
	}
}
